package org.gy.T4;

public class ExceptionTest2 {
    public static <AgeIllegalException extends Throwable> void main(String[] args) throws AgeIllegalException {
// 需求：保存⼀个合法的年
        saveAge(225);
        System.out.println("saveAge2底层执⾏是成功的！");
    }
    //2、在⽅法中对age进⾏判断，不合法则抛出AgeIllegalException
    public static void saveAge(int age){
        if(age > 0 && age < 150){
            System.out.println("年龄被成功保存： " + age);
        }else {
// ⽤⼀个异常对象封装这个问题
// throw 抛出去这个异常对象
            try {
                throw new AgeIllegalRuntimeException("/age is illegal, your age is" + age);
            } catch (AgeIllegalRuntimeException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
